using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Microsoft.Xna.Framework;

using HadronData;

namespace HadronEditor
{
    public partial class LevelPropertiesForm : Form
    {
        private Level m_level;

        private void m_btnOK_Click(object p_objSender, EventArgs p_eventArgs)
        {
            // validation
            bool bError = false;
            this.DialogResult = DialogResult.None;
            Vector2 vecDimensions = m_level.Dimensions;

            // width
            if (!float.TryParse(m_txtWidth.Text, out vecDimensions.X))
            {
                m_errorProvider.SetError(m_txtWidth, "Invalid value for level width");
                bError = true;
            }
            if (vecDimensions.X < 1024.0f)
            {
                m_errorProvider.SetError(m_txtWidth, "Width must be at least 1024 units");
                bError = true;
            }

            // height
            if (!float.TryParse(m_txtHeight.Text, out vecDimensions.Y))
            {
                m_errorProvider.SetError(m_txtHeight, "Invalid value for level height");
                bError = true;
            }
            if (vecDimensions.Y < 1024.0f)
            {
                m_errorProvider.SetError(m_txtHeight, "Height must be at least 1024 units");
                bError = true;
            }

            if (bError)
                return;

            // assign all values
            m_level.Name = m_txtName.Text;
            m_level.Dimensions = vecDimensions;


            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        public LevelPropertiesForm(Level p_level)
        {
            InitializeComponent();

            m_level = p_level;
            m_txtName.Text = m_level.Name;
            m_txtWidth.Text = m_level.Dimensions.X.ToString();
            m_txtHeight.Text = m_level.Dimensions.Y.ToString();
        }

        public String LevelName
        {
            get { return m_txtName.Text; }
            set { m_txtName.Text = value; }
        }

    }
}